package br.com.canvasForAll.model.dao;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import javax.ejb.Stateless;
import javax.inject.Named;
import javax.persistence.Query;

import br.com.canvasForAll.model.entity.Arquivo;
import br.com.canvasForAll.model.entity.Postit;
import br.com.canvasForAll.model.generic.dao.GenericCrudDao;
import br.com.canvasForAll.model.repository.ArquivoRepository;

@Stateless
@Named("arquivoRepository")
public class ArquivoDao extends GenericCrudDao<Arquivo> implements ArquivoRepository {

	public ArquivoDao() {
		super(Arquivo.class);
	}

	@Override
	public Arquivo obterId(Long entityId) throws Exception {
		return super.obterPorId(entityId);
	}

	@Override
	public List<Arquivo> obterExemplo(String namedQuery, Map<String, Object> parametros) throws Exception {
		return super.obterPorExemplo(namedQuery, getParametros());
	}

	@SuppressWarnings("unchecked")
	@Override
	public Collection<Arquivo> obterArquivoPostit(Postit postit) throws Exception {
		String sql = "SELECT a FROM Arquivo a WHERE a.postit = :postit ORDER BY a.dataUltimaAtualizacao";
		Query query = em.createQuery(sql);
		query.setParameter("postit", postit);
		
		return query.getResultList();
	}
	
}
